﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using FreeImageAPI;

namespace Imagenator.Controls
{
	partial class JpegSaveControl : SaveControl
	{
		public JpegSaveControl()
		{
			InitializeComponent();
		}

		protected override void OnLoad(EventArgs e)
		{
			Settings settings = Settings.Load();
			this.cbQuality.Select(settings.JpegQuality);
			this.cbSubsampling.Select(settings.JpegSubsampling);
			this.cbProgressive.Checked = settings.JpegProgressive;
			base.OnLoad(e);
		}

		public override void Close()
		{
			Settings settings = Settings.Load();
			settings.JpegQuality = this.cbQuality.SelectedItem;
			settings.JpegSubsampling = this.cbSubsampling.SelectedItem;
			settings.JpegProgressive = this.cbProgressive.Checked;
			base.Close();
		}

		protected override FREE_IMAGE_SAVE_FLAGS GetSaveFlags()
		{
			FREE_IMAGE_SAVE_FLAGS flags = base.GetSaveFlags() | FREE_IMAGE_SAVE_FLAGS.JPEG_OPTIMIZE;
			flags |= (FREE_IMAGE_SAVE_FLAGS)this.cbQuality.SelectedItem;
			flags |= (FREE_IMAGE_SAVE_FLAGS)this.cbSubsampling.SelectedItem;
			if (this.cbProgressive.Checked == true)
				flags |= FREE_IMAGE_SAVE_FLAGS.JPEG_PROGRESSIVE;
			return flags;
		}
	}
}
